<?php
namespace Home\Controller;
use Think\Controller;
class ShowController extends BaseController {

	public function _initialize(){
        $this->tbl1='groups';
        $this->tbl2='practices';
    
        parent::_initialize();
    }
    public function index(){
       parent::index($this->tbl1);
       parent::index($this->tbl2);
       parent::index($this->tbl3);
    }

    public function group(){
        $this->model=D($this->tbl1);
        $id=I('get.id');
        $list = $this->model->find($id);
        //dump($id);exit;
        $this->assign('one',$list);// 赋值数据集

        $this->assign('plist',M('practices')->where('id='.$id)->select());

        $this->assign('glist',M('members')->where('ydq_gid='.$id)->select());

        //
        $this->display();
    }
    public function practices(){
        $this->model=D($this->tbl2);
        $id=I('get.id');
        $list = $this->model->find($id);
        $this->assign('one',$list);// 赋值数据集

        $data = M('groups')->find($list['ydq_groupname']);

        $this->assign('data',$data);// 赋值数据集
        $this->assign('plist',M('members')->where('ydq_gid='.$id)->select());
        //dump($data);exit;
        $this->display();
    }



     public function joinclub(){
        $this->model=D('members');
        $data=session('users');
        //$this->assign('remmber',$data);
        $id=I('get.id'); 
        $condition1['ydq_stunum'] = $data['ydq_stunum'];
        $condition1['ydq_id'] = $id;
        $data1=$this->model->where($condition1)->select();
      //  $condition2['wl_state'] = 0;
        $condition2['ydq_stunum'] = $data['ydq_stunum'];
        $data2=M('members')->where($condition2)->select();
        $data3=M('groups')->find($id);
        if($data){
            if($data1){
                $this->error('已经是该社团成员');
            }
            elseif($data2){
                $this->error('您已经申请了，请耐心等待！');
            }
            else{
                $da['wl_id']=$id;
                //$da['wl_state']=0;
                $da['ydq_stunum']=$data['ydq_stunum'];
                $da['ydq_realname']=$data['ydq_realname'];
                if(M('members')->create($da)){
                    M('members')->add();
                    $this->success('申请成功,等待审核！',U('show/group'));
                }
                else{
                    $this->error(M('members')->getError());
                }
            }
        }
    }
    public function joinact(){
        $this->model=D('stuprac');
        $data=session('user');
        $id=I('get.id'); 
        $condition1['ydq_stunum'] = $data['ydq_stunum'];
        $condition1['ydq_id'] = $id;
        $data1=$this->model->where($condition1)->select();
        //$condition2['wl_state'] = 0;
        $condition2['ydq_stunum'] = $data['ydq_stunum'];
        $data2=$this->model->where($condition2)->select();
        $data3=M('practices')->find($id);
        if($data){
            if($data1){
                $this->error('已经参加该活动');
            }
            elseif($data2){
                $this->error('您已经申请了，请耐心等待！');
            }
            else{
                $da['ydq_id']=$id;
               // $da['wl_state']=0;
                $da['ydq_stunum']=$data['ydq_stunum'];
                $da['ydq_realname']=$data['ydq_realname'];
                if(M('stuprac')->create($da)){
                    M('stuprac')->add();
                    $this->success('申请成功,等待审核！',U('show/practices'));
                }
                else{
                    $this->error(M('stuprac')->getError());
                }
            }
        }
    }
}
